home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / migrate / RCS / mig.c,v < prev    next >
Encoding:
Text File  |  1991-06-13  |  18.2 KB  |  896 lines

  1. head     1.14;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.14
  10. date     90.09.24.14.38.37;  author douglis;  state Exp;
  11. branches ;
  12. next     1.13;
  13.  
  14. 1.13
  15. date     90.05.08.12.09.33;  author douglis;  state Exp;
  16. branches ;
  17. next     1.12;
  18.  
  19. 1.12
  20. date     90.02.20.15.00.36;  author douglis;  state Exp;
  21. branches ;
  22. next     1.11;
  23.  
  24. 1.11
  25. date     90.02.16.11.08.05;  author douglis;  state Exp;
  26. branches ;
  27. next     1.10;
  28.  
  29. 1.10
  30. date     90.01.03.17.33.12;  author douglis;  state Exp;
  31. branches ;
  32. next     1.9;
  33.  
  34. 1.9
  35. date     89.07.31.17.52.58;  author douglis;  state Exp;
  36. branches ;
  37. next     1.8;
  38.  
  39. 1.8
  40. date     89.07.12.13.29.55;  author douglis;  state Exp;
  41. branches ;
  42. next     1.7;
  43.  
  44. 1.7
  45. date     89.06.15.22.56.07;  author douglis;  state Exp;
  46. branches ;
  47. next     1.6;
  48.  
  49. 1.6
  50. date     89.05.05.10.37.29;  author douglis;  state Exp;
  51. branches ;
  52. next     1.5;
  53.  
  54. 1.5
  55. date     89.05.04.17.01.35;  author douglis;  state Exp;
  56. branches ;
  57. next     1.4;
  58.  
  59. 1.4
  60. date     88.12.21.15.59.07;  author douglis;  state Exp;
  61. branches ;
  62. next     1.3;
  63.  
  64. 1.3
  65. date     88.11.25.15.59.39;  author douglis;  state Exp;
  66. branches ;
  67. next     1.2;
  68.  
  69. 1.2
  70. date     88.11.19.17.31.34;  author douglis;  state Exp;
  71. branches ;
  72. next     1.1;
  73.  
  74. 1.1
  75. date     88.11.19.16.48.51;  author douglis;  state Exp;
  76. branches ;
  77. next     ;
  78.  
  79.  
  80. desc
  81. @Program to use process migration for remote execution.
  82. @
  83.  
  84.  
  85. 1.14
  86. log
  87. @allow user to specify background priority
  88. @
  89. text
  90. @/* 
  91.  * mig.c --
  92.  *
  93.  *    Program to perform remote execution using process migration.
  94.  *
  95.  * Copyright 1988 Regents of the University of California
  96.  * Permission to use, copy, modify, and distribute this
  97.  * software and its documentation for any purpose and without
  98.  * fee is hereby granted, provided that the above copyright
  99.  * notice appear in all copies.  The University of California
  100.  * makes no representations about the suitability of this
  101.  * software for any purpose.  It is provided "as is" without
  102.  * express or implied warranty.
  103.  */
  104.  
  105. #ifndef lint
  106. static char rcsid[] = "$Header: /sprite/src/cmds/mig/RCS/mig.c,v 1.13 90/05/08 12:09:33 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  107. #endif not lint
  108.  
  109.  
  110. #include <sprite.h>
  111. #include <status.h>
  112. #include <option.h>
  113. #include <proc.h>
  114. #include <stdio.h>
  115. #include <stdlib.h>
  116. #include <host.h>
  117. #include <sys/wait.h>
  118. #include <signal.h>
  119. #include <string.h>
  120. #include <errno.h>
  121. #include <mig.h>
  122.  
  123. /*
  124.  * Library imports:
  125.  */
  126.  
  127. extern char **environ;
  128.  
  129. /*
  130.  * Forward declarations
  131.  */
  132. static void DoExec();
  133. static int RemotePathExec();
  134.  
  135. int debug = 0;
  136. char *host = NULL;
  137. int hostID = -1;
  138. char *procIDString = NULL;
  139. int local = 0;
  140. int background = 0;
  141. int backPrio = 0;
  142. int verbose = 0;
  143. char *execName = NULL;
  144.  
  145. Option optionArray[] = {
  146.     {OPT_STRING, "h", (Address) &host,
  147.      "String identifier for host to migrate onto (default is random selection)."},
  148.     {OPT_INT, "H", (Address) &hostID,
  149.      "Numeric identifier for host to migrate onto."},
  150.     {OPT_TRUE, "b", (Address) &background,
  151.      "Execute command in background and print processID."},
  152.     {OPT_TRUE, "B", (Address) &backPrio,
  153.      "Execute command at background priority."},
  154.     {OPT_TRUE, "l", (Address) &local,
  155.      "Execute command locally if no idle node is available."},
  156.     {OPT_TRUE, "D", (Address) &debug,
  157.      "Enable debugging messages."},
  158.     {OPT_STRING, "E", (Address) &execName,
  159.      "Exec the command specified by this argument, setting argv[0] to the first argument following the option list."},
  160.     {OPT_TRUE, "v", (Address) &verbose,
  161.      "Print useful information, such as which host is selected."},
  162.     {OPT_STRING, "p", (Address) &procIDString,
  163.      "Process ID of process to migrate (default is to start shell, or issue command given as remaining arguments)"},
  164. };
  165.  
  166. /*
  167.  * Default shell to invoke if none found in environment.
  168.  */
  169. #define SHELL "csh"
  170.  
  171. main(argc, argv)
  172.     int  argc;
  173.     char *argv[];
  174. {
  175.     ReturnStatus status;
  176.     char *myName;
  177.     char **argArray;
  178.     char *shell;
  179.     int pid;
  180.     Host_Entry *hostPtr;
  181.     int i;
  182.     int selectedHost;
  183.     int doCmd;
  184.     int procID;
  185.     int flags;
  186.     
  187.     argc = Opt_Parse(argc, argv, optionArray, Opt_Number(optionArray), 
  188.              OPT_ALLOW_CLUSTERING|OPT_OPTIONS_FIRST);
  189.  
  190.     myName = argv[0];
  191.     if (hostID != -1 && host != (char *) NULL) {
  192.     fprintf(stderr, "%s: -h and -H options are mutually exclusive\n",
  193.         myName);
  194.     exit(1);
  195.     }
  196.     if (debug) {
  197.     verbose = 1;
  198.     }
  199.     if (procIDString != (char *) NULL) {
  200.     if (background) {
  201.         fprintf(stderr, "%s: -b and -p options are mutually exclusive\n",
  202.             myName);
  203.         exit(1);
  204.     }
  205.     procID = strtol(procIDString, (char **) NULL, 16);
  206.     if (procID <= 0) {
  207.         (void)fprintf(stderr, "%s: invalid process ID: %s.\n", myName,
  208.               procIDString);
  209.         exit(1);
  210.     }
  211.     doCmd = 0;
  212.     if (argc > 1) {
  213.         (void)fprintf(stderr, "%s: extra arguments ignored.\n", myName);
  214.     }
  215.     if (local) {
  216.         (void)fprintf(stderr,
  217.               "%s: -l argument ignored when migrating process.\n",
  218.               myName);
  219.         local = 0;
  220.     }
  221.     flags = MIG_PROC_AGENT;
  222.     } else {
  223.     doCmd = 1;
  224.     procID = PROC_MY_PID;
  225.     if (argc == 1) {
  226.         argArray = (char **) malloc(2 * sizeof(char *));
  227.         shell = getenv("SHELL");
  228.         if (shell == (char *) NULL) {
  229.         shell = SHELL;
  230.         }
  231.         argArray[0] = shell;
  232.             execName = shell;
  233.         argArray[1] = NULL;
  234.     } else {
  235.         argArray = &argv[1];
  236.         if (!execName) {
  237.         execName = argArray[0];
  238.         }
  239.     }
  240.     flags = background ? MIG_PROC_AGENT : 0;
  241.     }  
  242.     if (host != (char *) NULL) {
  243.     selectedHost = 0;
  244.     hostPtr = Host_ByName(host);
  245.     if (hostPtr == (Host_Entry *) NULL) {
  246.         fprintf(stderr, "%s: %s: no such host.\n", myName, host);
  247.         exit(1);
  248.     }
  249.     hostID = hostPtr->id;
  250.     Host_End();
  251.     } else if (hostID != -1) {
  252.     selectedHost = 0;
  253.     } else {
  254.     int hostNumbers[1];
  255.     int hostsAssigned;
  256.     
  257.     selectedHost = 1;
  258.     (void) signal(SIGINT, SIG_IGN);
  259.     hostsAssigned = Mig_RequestIdleHosts(1, backPrio ?
  260.                          MIG_LOW_PRIORITY :
  261.                          MIG_NORMAL_PRIORITY,
  262.                          flags,
  263.                          (void (*)()) NULL, hostNumbers);
  264.     if (hostsAssigned < 0) {
  265.         perror("Mig_RequestIdleHosts");
  266.         exit(1);
  267.     }
  268.     if (hostsAssigned == 0) {
  269.         if (!local) {
  270.         fprintf(stderr, "%s: no idle host available.\n", myName);
  271.         exit(1);
  272.         }
  273.         hostID = 0;
  274.     } else {
  275.         hostID = hostNumbers[0];
  276.     }
  277.     if (verbose) {
  278.         if (hostID) {
  279.         hostPtr = Host_ByID(hostID);
  280.         if (hostPtr == (Host_Entry *) NULL) {
  281.             fprintf(stderr, "%s: unable to find host %d.\n",
  282.                 myName, hostID);
  283.             exit(1);
  284.         }
  285.         fprintf(stderr, "%s: migrating to host %s.\n", myName,
  286.             hostPtr->name);
  287.         Host_End();
  288.         } else {
  289.         fprintf(stderr,
  290.             "%s: no idle host available; running locally.\n",
  291.             myName);
  292.         }
  293.     }
  294.     }
  295.  
  296.     if ((selectedHost || background) && hostID && doCmd) {
  297.     /*
  298.      * Wait for the process to complete so we can register that we're
  299.      * through with the host.
  300.      */
  301.     pid = fork();
  302.     if (pid < 0) {
  303.         perror("Error forking child");
  304.         exit(1);
  305.     }
  306.         
  307.     if (pid) {
  308.         union wait status;
  309.         int error;
  310.         int exited = 0;
  311.         int exitCode;
  312.  
  313.  
  314.         if (background) {
  315.         printf("%x\n", pid);
  316.         exit(0);
  317.         }
  318.         do {
  319.         
  320.         error = wait(&status);
  321.         if (error == -1) {
  322.             perror("wait");
  323.             exit(1);
  324.         } else if (error != pid && debug) {
  325.             (void) fprintf(stderr, "%s: received status %d from wait.\n",
  326.                    myName, error);
  327.         } else if (error == pid) {
  328.             if (status.w_stopval != WSTOPPED) {
  329.             exited = 1;
  330.             if (status.w_termsig != 0) {
  331.                 if (debug) {
  332.                 (void) fprintf(stderr,
  333.                            "%s: process was signalled.\n",
  334.                            myName);
  335.                 }
  336.                 exitCode = status.w_termsig;
  337.             } else {
  338.                 exitCode = status.w_retcode;
  339.             }
  340.             } else {
  341.             if (debug) {
  342.                 (void) fprintf(stderr,
  343.                        "%s: process was suspended.\n",
  344.                        myName);
  345.             }
  346.             }
  347.         }
  348.         } while (!exited);
  349. #ifdef undef
  350.         if (debug) {
  351.         (void) fprintf(stderr,
  352.                    "%s: Exited(%d).  Calling Mig_Done(%d).\n",
  353.                    myName, exitCode, hostID);
  354.         (void) fflush(stderr);
  355.         }
  356.         (void) Mig_Done(hostID);
  357. #endif
  358.         exit(exitCode);
  359.     } else {
  360.         (void) signal(SIGINT, SIG_DFL);
  361.     }
  362.     }
  363.     if (hostID && !doCmd) {
  364.     /*
  365.      * We're migrating someone else.
  366.      */
  367.     
  368.     if (debug) {
  369.         (void) fprintf(stderr, "Calling Proc_Migrate(%d, %d).\n", procID,
  370.                hostID);
  371.         (void) fflush(stderr);
  372.     }
  373.     
  374.     status = Proc_Migrate(procID, hostID);
  375.     if (status != SUCCESS) {
  376.         fprintf(stderr, "%s: error in Proc_Migrate: %s\n",
  377.             myName, Stat_GetMsg(status));
  378.         fflush(stderr);
  379.         if (!local) {
  380.         exit(1);
  381.         }
  382.     }
  383.     }
  384.     if (!doCmd) {
  385.     exit(0);
  386.     }
  387.     /*
  388.      * Still the child here, or the only process if we were running locally
  389.      * and never forked.
  390.      */
  391.     if (debug) {
  392.     (void) fprintf(stderr, "Calling RemotePathExec(%s,...,%d).\n",
  393.                execName, hostID);
  394.     (void) fflush(stderr);
  395.     }
  396.     status = RemotePathExec(execName, argArray, hostID);
  397.     perror("Error execing program");
  398.     exit(status);
  399. }
  400.  
  401.  
  402. /*
  403.  *-----------------------------------------------------------------------
  404.  *
  405.  * DoExec --
  406.  *
  407.  *    Function to actually execute a program. If the exec didn't succeed
  408.  *    because the file isn't in a.out format, attempt to execute
  409.  *    it as a bourne shell script.
  410.  *
  411.  * Results:
  412.  *    None.  Doesn't even return unless the exec failed.
  413.  *
  414.  * Side Effects:
  415.  *    A program may be execed over this one.
  416.  *
  417.  *-----------------------------------------------------------------------
  418.  */
  419.  
  420. static void
  421. DoExec(file, argv, hostID)
  422.     char *file;            /* File to execute. */
  423.     char **argv;        /* Arguments to the program. */
  424.     int hostID;            /* ID of host on which to exec */
  425. {
  426.     ReturnStatus status;
  427.     status = Proc_RemoteExec(file, argv, environ, hostID);
  428.     if (debug) {
  429.     fprintf(stderr, "Proc_RemoteExec(\"%s\"): %s\n", file,
  430.         Stat_GetMsg(status));
  431.     }
  432.     errno = Compat_MapCode(status);
  433.     if (errno == ENOEXEC) {
  434.     /*
  435.      * Attempt to execute the file as a shell script using
  436.      * the Bourne shell)
  437.      */
  438.     register char **newargv;
  439.     register int i;
  440.  
  441.     for (i = 0; argv[i] != 0; i++) {
  442.         /* Empty loop body */
  443.     }
  444.     newargv = (char **) malloc((unsigned) ((i+1)*sizeof (char *)));
  445.     newargv[0] = "sh";
  446.     newargv[1] = file;
  447.     for (i = 1; argv[i] != 0; i++) {
  448.         newargv[i+1] = argv[i];
  449.     }
  450.     newargv[i+1] = 0;
  451.     status = Proc_RemoteExec("/sprite/cmds/sh", newargv, environ, hostID);
  452.     errno = Compat_MapCode(status);
  453.     }
  454. }
  455.  
  456. /*
  457.  *----------------------------------------------------------------------
  458.  *
  459.  * RemotePathExec --
  460.  *
  461.  *    Execute a process, using the current environment variable,
  462.  *    instead of an explicitly-supplied one.  Also, imitate the
  463.  *    shell's actions in trying each directory in a search path
  464.  *    (given by the "PATH" environment variable).  Also, specify
  465.  *    a remote host.  This is taken from the library execve call.
  466.  *
  467.  * Results:
  468.  *    This procedure returns only if the exec fails.  In this case
  469.  *    the return value is -1.
  470.  *
  471.  * Side effects:
  472.  *    Overlays the current process with a new image.  See the man
  473.  *    page for details.
  474.  *
  475.  *----------------------------------------------------------------------
  476.  */
  477.  
  478. static int
  479. RemotePathExec(name, argv, hostID)
  480.     char *name;            /* Name of file containing program to exec. */
  481.     char **argv;        /* Array of arguments to pass to program. */
  482.     int hostID;            /* ID of host on which to exec */
  483. {
  484.     char *path;
  485.     char *fullName;
  486.     register char *first, *last;
  487.     int size, noAccess;
  488.  
  489.     noAccess = 0;
  490.  
  491.     if (index(name, '/') != 0) {
  492.     /*
  493.      * If the name specifies a path, don't search for it on the search path,
  494.      * just try and execute it.
  495.      */
  496.     DoExec(name, argv, hostID);
  497.     return -1;
  498.     }
  499.  
  500.     path = getenv("PATH");
  501.     if (path == 0) {
  502.     path = "/sprite/cmds";
  503.     }
  504.     fullName = malloc((unsigned) (strlen(name) + strlen(path)) + 2);
  505.     for (first = path; ; first = last+1) {
  506.  
  507.     /*
  508.      * Generate the next file name to try.
  509.      */
  510.  
  511.     for (last = first; (*last != 0) && (*last != ':'); last++) {
  512.         /* Empty loop body. */
  513.     }
  514.     size = last-first;
  515.     (void) strncpy(fullName, first, size);
  516.     if (last[-1] != '/') {
  517.         fullName[size] = '/';
  518.         size++;
  519.     }
  520.     (void) strcpy(fullName + size, name);
  521.  
  522.     if (debug) {
  523.         fprintf(stderr, "Trying DoExec(\"%s\")....\n", fullName);
  524.     }
  525.     DoExec(fullName, argv, hostID);
  526.     if (debug) {
  527.         fprintf(stderr, "DoExec(\"%s\") => %d.\n", fullName, errno);
  528.     }
  529.     if (errno == EACCES) {
  530.         noAccess = 1;
  531.     } else if (errno != ENOENT) {
  532.         break;
  533.     }
  534.     if (*last == 0) {
  535.         /*
  536.          * Hit the end of the path. We're done.
  537.          * If there existed a file by the right name along the search path,
  538.          * but its permissions were wrong, return FS_NO_ACCESS. Else return
  539.          * whatever we just got back.
  540.          */
  541.         if (noAccess) {
  542.         errno = EACCES;
  543.         }
  544.         break;
  545.     }
  546.     }
  547.     free((char *) fullName);
  548.     return -1;
  549. }
  550. @
  551.  
  552.  
  553. 1.13
  554. log
  555. @added -b for background option.
  556. @
  557. text
  558. @d17 1
  559. a17 1
  560. static char rcsid[] = "$Header: /sprite/src/cmds/mig.new/RCS/mig.c,v 1.12 90/02/20 15:00:36 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  561. d52 1
  562. d63 2
  563. d170 3
  564. a172 1
  565.     hostsAssigned = Mig_RequestIdleHosts(1, MIG_NORMAL_PRIORITY,
  566. @
  567.  
  568.  
  569. 1.12
  570. log
  571. @use Mig_RequestIdleHosts.
  572. ./
  573. @
  574. text
  575. @d17 1
  576. a17 1
  577. static char rcsid[] = "$Header: /user2/douglis/pdev_mig/src/cmds/mig/RCS/mig.c,v 1.11 90/02/11 21:55:35 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  578. d51 1
  579. d60 2
  580. d93 1
  581. d108 5
  582. d129 1
  583. d148 1
  584. d168 1
  585. a168 1
  586.                          doCmd ? 0 : MIG_PROC_AGENT,
  587. d202 1
  588. a202 1
  589.     if (selectedHost && hostID && doCmd) {
  590. d219 5
  591. d255 1
  592. d263 1
  593. @
  594.  
  595.  
  596. 1.11
  597. log
  598. @debugging statements
  599. @
  600. text
  601. @d17 1
  602. a17 1
  603. static char rcsid[] = "$Header: /sprite/src/cmds/mig/RCS/mig.c,v 1.10 90/01/03 17:33:12 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  604. d32 1
  605. d151 3
  606. d156 5
  607. a160 3
  608.     hostID = Mig_GetIdleNode();
  609.     if (hostID < 0) {
  610.         perror("Mig_GetIdleNode");
  611. d163 8
  612. a170 3
  613.     if (hostID == 0 && !local) {
  614.         fprintf(stderr, "%s: no idle host available.\n", myName);
  615.         exit(1);
  616. @
  617.  
  618.  
  619. 1.10
  620. log
  621. @changed Proc_RawRemoteExec to Proc_RemoteExec calls.
  622. @
  623. text
  624. @d17 1
  625. a17 1
  626. static char rcsid[] = "$Header: /sprite/src/cmds/mig/RCS/mig.c,v 1.9 89/07/31 17:52:58 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  627. d305 4
  628. d399 3
  629. d403 3
  630. @
  631.  
  632.  
  633. 1.9
  634. log
  635. @removed lint
  636. @
  637. text
  638. @d17 1
  639. a17 1
  640. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.8 89/07/12 13:29:55 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  641. d250 1
  642. d304 1
  643. a304 1
  644.     status = Proc_RawExec(file, argv, environ, 0, hostID);
  645. d324 1
  646. a324 1
  647.     status = Proc_RawExec("/sprite/cmds/sh", newargv, environ, 0, hostID);
  648. @
  649.  
  650.  
  651. 1.8
  652. log
  653. @use remote exec instead of migrate + local exec
  654. @
  655. text
  656. @d17 1
  657. a17 1
  658. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.7 89/06/15 22:56:07 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  659. a30 1
  660. #include <stdlib.h>
  661. d350 1
  662. a350 1
  663. int
  664. @
  665.  
  666.  
  667. 1.7
  668. log
  669. @allow hostID instead of hostName, for efficiency
  670. @
  671. text
  672. @d17 1
  673. a17 1
  674. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.6 89/05/05 10:37:29 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  675. d30 9
  676. d40 6
  677. d241 1
  678. a241 1
  679.     if (hostID) {
  680. d243 1
  681. a243 2
  682.      * We're the child, or we were directed to a particular host so
  683.      * we never forked, or we're migrating someone else.
  684. d269 2
  685. a270 1
  686.     (void) fprintf(stderr, "Calling execvp(%s,...).\n", execName);
  687. d273 1
  688. a273 1
  689.     status = execvp(execName, argArray);
  690. d276 140
  691. @
  692.  
  693.  
  694. 1.6
  695. log
  696. @fixed bug i introduced regarding name to exec if no arg specified.
  697. @
  698. text
  699. @d17 1
  700. a17 1
  701. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.5 89/05/04 17:01:35 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  702. d29 1
  703. d33 1
  704. d41 3
  705. a43 1
  706.      "Host to migrate onto (default is random selection)."},
  707. a69 1
  708.     int hostID;
  709. d80 5
  710. d133 2
  711. d137 1
  712. d222 2
  713. @
  714.  
  715.  
  716. 1.5
  717. log
  718. @added capability to separate exec name and argv[0] via -E option.
  719. useful for pmake.
  720. @
  721. text
  722. @d17 1
  723. a17 1
  724. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.4 88/12/21 15:59:07 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  725. d107 1
  726. @
  727.  
  728.  
  729. 1.4
  730. log
  731. @allow mig to migrate a particular process when given "-p pid".
  732. @
  733. text
  734. @d17 1
  735. a17 1
  736. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.3 88/11/25 15:59:39 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  737. d35 1
  738. d44 2
  739. d110 3
  740. d116 1
  741. a116 1
  742.     selectedHost = 1;
  743. d125 1
  744. a125 1
  745.     selectedHost = 0;
  746. d241 1
  747. a241 1
  748.     (void) fprintf(stderr, "Calling execvp(%s,...).\n", argArray[0]);
  749. d244 1
  750. a244 1
  751.     status = execvp(argArray[0], argArray);
  752. @
  753.  
  754.  
  755. 1.3
  756. log
  757. @exit w/ status from process exec'ed.  added verbose mode.  changed to
  758. use modified Opt library call that stops parsing when it hits a non-option.
  759. therefore gets rid of "-x" option.
  760. @
  761. text
  762. @d17 1
  763. a17 1
  764. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.2 88/11/19 17:31:34 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  765. d32 1
  766. d38 1
  767. a38 1
  768.     "Host to migrate onto (default is random selection)."},
  769. d40 1
  770. a40 1
  771.     "Execute command locally if no idle node is available."},
  772. d42 1
  773. a42 1
  774.     "Enable debugging messages."},
  775. d44 3
  776. a46 1
  777.     "Print useful information, such as which host is selected."},
  778. d67 3
  779. a69 1
  780.  
  781. d77 6
  782. a82 6
  783.  
  784.     if (argc == 1) {
  785.     argArray = (char **) malloc(2 * sizeof(char *));
  786.     shell = getenv("SHELL");
  787.     if (shell == (char *) NULL) {
  788.         shell = SHELL;
  789. d84 10
  790. a93 2
  791.     argArray[0] = shell;
  792.     argArray[1] = NULL;
  793. d95 14
  794. a108 3
  795.     argArray = &argv[1];
  796.     }
  797.         
  798. d148 1
  799. a148 1
  800.     if (selectedHost && hostID) {
  801. d158 1
  802. d205 2
  803. d209 1
  804. a209 1
  805.      * we never forked.
  806. d211 1
  807. d213 2
  808. a214 1
  809.         (void) fprintf(stderr, "Calling Proc_Migrate(%d).\n", hostID);
  810. d217 1
  811. a217 1
  812.     status = Proc_Migrate(PROC_MY_PID, hostID);
  813. d226 3
  814. @
  815.  
  816.  
  817. 1.2
  818. log
  819. @fixed bugs, seems to work now.
  820. @
  821. text
  822. @d17 1
  823. a17 1
  824. static char rcsid[] = "$Header: /a/newcmds/mig/RCS/mig.c,v 1.1 88/11/19 16:48:51 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  825. d26 1
  826. d28 1
  827. d33 1
  828. a33 1
  829. int rest;
  830. d41 3
  831. a43 3
  832.     "Enable debugging of this program."},
  833.     {OPT_REST, "x", (Address) &rest,
  834.     "Treat remaining arguments as command to execute."},
  835. d46 5
  836. d58 1
  837. d63 1
  838. d66 1
  839. a66 1
  840.              OPT_ALLOW_CLUSTERING);
  841. d69 3
  842. d75 5
  843. a79 1
  844.     argArray[0] = "csh";
  845. d86 1
  846. d95 1
  847. d105 17
  848. d124 5
  849. a128 1
  850.     if (hostID) {
  851. d135 36
  852. a170 1
  853.         (void) wait(0);
  854. d172 3
  855. a174 1
  856.         (void) fprintf(stderr, "Calling Mig_Done(%d).\n", hostID);
  857. d178 1
  858. a178 1
  859.         exit(0);
  860. d181 2
  861. a182 1
  862.      * We're the child.
  863. d190 1
  864. a190 1
  865.         fprintf(stderr, "%s: error in Proc_Migrate: %s",
  866. @
  867.  
  868.  
  869. 1.1
  870. log
  871. @Initial revision
  872. @
  873. text
  874. @d17 1
  875. a17 1
  876. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  877. d31 1
  878. d34 1
  879. a34 1
  880.     {OPT_STRING, 'h', (Address) &host,
  881. d36 1
  882. a36 1
  883.     {OPT_TRUE, 'l', (Address) &local,
  884. d38 4
  885. d52 3
  886. d56 1
  887. a56 1
  888.     (void) Opt_Parse(&argc, argv, Opt_Number(optionArray), optionArray,
  889. d62 1
  890. a62 1
  891.     argArray = (char **) malloc(2, sizeof(char *));
  892. d75 1
  893. a75 1
  894.     hostID = hostPtr->spriteID;
  895. @
  896.